package xby.study.proxy.cglib;

import net.sf.cglib.proxy.*;

import java.lang.reflect.Method;

public class MergedCallbacks {


    static class MyCallbackFilter implements CallbackFilter {
        @Override
        public int accept(Method method) {
            System.out.println("方法信息：" + method);
            return 0;
        }
    }

    static class Callback1 implements NoOp {
    }

    static class Callback2 implements MethodInterceptor {
        @Override
        public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
            return null;
        }
    }

    public void f() {
        System.out.println(">>>>插进来了!");
    }

    public static void main(String[] args) {
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(MergedCallbacks.class);
        Callback[] callbacks = new Callback[2];
        callbacks[0] = new Callback1();
        callbacks[1] = new Callback2();
        enhancer.setCallbacks(callbacks);
        enhancer.setCallbackFilter(new MyCallbackFilter());
        MergedCallbacks proxy = (MergedCallbacks) enhancer.create();
        proxy.f();

    }
}
